﻿Imports lbGlobalcom

Public Class FrmPPal
    Const EnsabladoPPal As String = "GlobalcomApp"
    
    Private Sub DescuentoRangosPreciosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DescuentoRangosPreciosToolStripMenuItem.Click
        Try
            Dim frDtoRP As New fDtoRangoPrecios
            frDtoRP.MdiParent = Me
            frDtoRP.WindowState = FormWindowState.Maximized
            frDtoRP.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ZonasToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZonasToolStripMenuItem1.Click
        Try
            Dim fZon As New fZonas
            fZon.MdiParent = Me
            fZon.WindowState = FormWindowState.Maximized
            fZon.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ErroresToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ErroresToolStripMenuItem.Click
        Try
            Dim fErr As New fErrores
            fErr.MdiParent = Me
            fErr.WindowState = FormWindowState.Maximized
            fErr.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


    Private Sub CargarMenu()
        Try
            tvMenu.Nodes.Clear()
            Dim mn As cMenu = New cMenu(CustomPrincipal.IDUsuario, tvMenu, ImgList, 1)
            tvMenu.ExpandAll()
            For Each Nodo As TreeNode In tvMenu.Nodes(0).Nodes
                Nodo.Collapse()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        
    End Sub
    Private Sub FrmPPal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim Log As New fLoguin
            If Log.ShowDialog = Windows.Forms.DialogResult.OK Then
                cApp.RefrescaCadConn(lbGlobalcom.CustomPrincipal.UserID, lbGlobalcom.CustomPrincipal.Pass)
                txtInfoApp.Text = Log.DatosLogueo
                CargarMenu()
                Me.WindowState = FormWindowState.Maximized
                If CustomPrincipal.IsInRole("ADMINGC") Then
                    AdministracionToolStripMenuItem.Enabled = True
                Else
                    AdministracionToolStripMenuItem.Enabled = False
                End If
            Else
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub CofiguracionConnToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CofiguracionConnToolStripMenuItem.Click
        Try
            Dim fConn As New frmConn
            fConn.MdiParent = Me
            fConn.WindowState = FormWindowState.Maximized
            fConn.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ClavesPrimariasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClavesPrimariasToolStripMenuItem.Click
        Try
            Dim fClavePrimaria As New fClavesPrimarias
            fClavePrimaria.MdiParent = Me
            fClavePrimaria.WindowState = FormWindowState.Maximized
            fClavePrimaria.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub UsuariosYGruposToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsuariosYGruposToolStripMenuItem.Click
        Try
            Dim fUsuaGrup As New fUserYRoles
            fUsuaGrup.MdiParent = Me
            fUsuaGrup.WindowState = FormWindowState.Maximized
            fUsuaGrup.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub DatosUsuariosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DatosUsuariosToolStripMenuItem.Click
        Try
            Dim fDatUs As New fDatosUsuarios
            fDatUs.MdiParent = Me
            fDatUs.WindowState = FormWindowState.Maximized
            fDatUs.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub CambioInicioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CambioInicioToolStripMenuItem.Click
        Try
            Dim fLog As New fLoguin
            If fLog.ShowDialog = Windows.Forms.DialogResult.OK Then
                cApp.RefrescaCadConn(lbGlobalcom.CustomPrincipal.UserID, lbGlobalcom.CustomPrincipal.Pass)
                txtInfoApp.Text = fLog.DatosLogueo
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub MenusToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenusToolStripMenuItem.Click
        Try
            Dim fAdmMenu As New fAdminMenus
            fAdmMenu.MdiParent = Me
            fAdmMenu.WindowState = FormWindowState.Maximized
            fAdmMenu.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub AbreForma(ByVal Ensablado As String)
        Try
            Dim Tipo As Type = System.Type.GetType(Ensablado)
            Dim Formulario As Form = Activator.CreateInstance(Tipo)
            Formulario.MdiParent = Me
            Formulario.WindowState = FormWindowState.Maximized
            Formulario.Show()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Private Sub tvMenu_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvMenu.NodeMouseClick
        If e.Node.Tag <> 0 Then
            Dim MiMnObj As ObjetosMN = New ObjetosMN(e.Node.Tag)
            If MiMnObj.TipoObjeto = 1 Then
                AbreForma(EnsabladoPPal & "." & MiMnObj.NombreObjeto)
            End If
        End If
    End Sub

    
    Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub ReconstruyeInventariosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim fRecInven As New fReconstruyePeriodo
            fRecInven.MdiParent = Me
            fRecInven.WindowState = FormWindowState.Maximized
            fRecInven.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub GeneraPlanoConversionesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim fGenPlano As New fGeneraPlanoConverCodigo
            fGenPlano.MdiParent = Me
            fGenPlano.WindowState = FormWindowState.Maximized
            fGenPlano.Show()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class
